package leetcode;

import java.util.*;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-10-18 17:59
 **/
public class LeetCode454 {

    public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
        Map<Integer, Integer> map = new HashMap<>();
        int count = 0;
        for (int i : nums1) {
            for (int i1 : nums2) {
                map.put(i + i1, map.getOrDefault(i + i1, 0) + 1);
            }
        }
        for (int i : nums3) {
            for (int i1 : nums4) {
                if (map.containsKey(-(i + i1))) {
                    count += map.get(-(i + i1));
                }
            }
        }
        return count;
    }

}
